package com.website.quartz.job;

import com.website.mybatis.entity.Quartz;
import com.website.quartz.service.QuartzTimerService;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.quartz.QuartzJobBean;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 * <p>@author zhangshuw
 * <p>2018/7/27
 */
public class InitQuartzJob extends QuartzJobBean {

    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Resource
    QuartzTimerService service;

    @Override
    protected void executeInternal(JobExecutionContext context) {
        try {
            List<Quartz> qtList = service.findJobs();
            for(Quartz qtm :qtList){
                service.getMgr().registerJobToScheduler(qtm);
            }
        } catch (Exception e) {
            log.error(e.toString(), e);
        }
    }
}
